package com.vision.world.survey.fragments;

import android.annotation.SuppressLint;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.vision.world.survey.R;
import com.vision.world.survey.presenter.SettingLayerPresenter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class IndentifyResultFragment extends Fragment {
    private Context mContext;
    
    private TextView txtKey1;
    private TextView txtKey2;
    private TextView txtKey3;
    private TextView txtValue1;
    private TextView txtValue2;
    private TextView txtValue3;
    private List<TextView> txtList=new ArrayList<>();
    private Map<String, Object> sResult=null;


    public IndentifyResultFragment(){}

    @SuppressLint({"NewApi", "ValidFragment"})
    public IndentifyResultFragment(Context context ) {
        // Required empty public constructor
        mContext=context;
    }

    public void setsResult(Map<String, Object> result){

        sResult=result;
        //刷新界面
        setResultInfo();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.layout_search_result, container, false);

        txtKey1=(TextView)view.findViewById(R.id.txt_result_key1);
        txtKey2=(TextView)view.findViewById(R.id.txt_result_key2);
        txtKey3=(TextView)view.findViewById(R.id.txt_result_key3);
        txtValue1=(TextView)view.findViewById(R.id.txt_result_value1);
        txtValue2=(TextView)view.findViewById(R.id.txt_result_value2);
        txtValue3=(TextView)view.findViewById(R.id.txt_result_value3);
        txtList.clear();
        txtList.add(txtKey1);
        txtList.add(txtValue1);
        txtList.add(txtKey2);
        txtList.add(txtValue2);
        txtList.add(txtKey3);
        txtList.add(txtValue3);
        setResultInfo();
        return view;
    }

    public void setResultInfo(){
        if (sResult!=null) {
            Set<String> resultk = sResult.keySet();
            Log.i("boundary", "" + resultk.size());
            int i = 0;
            for (String key : resultk) {
                if (!key.equals("FID") && !key.equals("GOE") && !key.equals("LAYERNAME") && !key.equals("OBJECTID") && !key.equals("Shape")) {
                    txtList.get(i).setText(key + "：");
                    i++;
                    txtList.get(i).setText(sResult.get(key).toString());
                    i++;
                    Log.i("Identify", key + "：" + sResult.get(key).toString());
                }
            }
        }
    }



}
